import java.util.ArrayList;
import java.util.Iterator;

public class StudenTList {
    public static void main(String[] args) {

        // 创建一个学生列表
        ArrayList<Student> students = new ArrayList<>();

        // 添加学生
        students.add(new Student(1, "张三"));
        students.add(new Student(2, "李四"));
        students.add(new Student(3, "王五"));

        // 输出所有学生信息
        System.out.println("初始学生列表：");
        for (Student student : students) {
            System.out.println(student);
        }

        // 查找并修改“张三”的姓名
        Iterator<Student> iterator = students.iterator();
        while (iterator.hasNext()) {
            Student student = iterator.next();
            if ("张三".equals(student.getName())) {
                student.setName("张三丰");
                break;
            }
        }

        // 输出修改后的学生列表
        System.out.println("修改张三姓名后：");
        for (Student student : students) {
            System.out.println(student);
        }

        // 查找并删除“王五”
        iterator = students.iterator();
        while (iterator.hasNext()) {
            Student student = iterator.next();
            if ("王五".equals(student.getName())) {
                iterator.remove();
                break;
            }
        }

        // 输出删除后的学生列表
        System.out.println("删除王五后：");
        for (Student student : students) {
            System.out.println(student);
        }
    }
}

class Student {
    private int id;
    private String name;

    public Student(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Student{" +
                "id=" + id +
                ", name='" + name + '\'' +
                '}';
    }
}
